package lu.med.praxiswahl.wahlumed.client.rechnungen.op.controller;

import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import lu.med.praxiswahl.wahlumed.client.rechnungen.op.model.OPSettlementCodeTableModel;

public class OPSettlementTableSelectionListener implements ListSelectionListener
{
    private OPSettlementCodeTableModel model;
    
    public OPSettlementTableSelectionListener(OPSettlementCodeTableModel model)
    {
	this.model = model;
    }

    @Override
    public void valueChanged(ListSelectionEvent e)
    {
	if (e.getValueIsAdjusting())
	{
	    return;
	}
	ListSelectionModel lsm = (ListSelectionModel) e.getSource();
	if (lsm.isSelectionEmpty())
	{
	    model.setSelected(-1);
	}
	else
	{
	    int selectedRow = lsm.getMinSelectionIndex();
	    model.setSelected(selectedRow);
	}
	
    }

}
